<?php
 /*
  *微商城商品模型模型类
  *@author 
  * <!--blakefan 1621743934@qq.com -->
  */
namespace Home\Model; 
use Think\Model;
class ItemDetailModel 
{
	public function index()
	{
		$result=array();
		$itemid=I('get.itemid',0,'strip_tags');
		if(empty($itemid)){return ''; }
		$item=M('item');
		$where['itemid']=intval($itemid);
		$where['platid']=array('gt',0);
		$result['iteminfo']=$item->where($where)->getField('itemid,itemname,bn,price,itemimg');
		$result['itemdesc']=M('item_desc')->where('itemid=%d',$itemid)->getField('itemdesc');
		//获取商品属性
		$result['attr']=$this->getItemAttr($itemid);

		if(!empty($result['iteminfo']) && !empty($result['itemdesc']) )
		{
			return $result;
		}else{
			return '';
		}


	}
	//获取商品属性
	private function getItemAttr($itemid)
	{
		$result=array();
		$itemid=!empty($itemid)?intval($itemid):0;
		if(empty($itemid)){return '';}
		$result=M()->cache(true)->query('SELECT a.`propertyid`,b.`propertyname`,a.`propertyvalueid`,c.`propertyvalue` FROM '.C('DB_PREFIX').'item_property a INNER JOIN  '.C('DB_PREFIX').'type_property b  ON a.`propertyid`=b.`propertyid` LEFT JOIN '.C('DB_PREFIX').'type_propertyvalue c ON  a.`propertyvalueid`=c.`valueid`WHERE a.`itemid`='.$itemid);
		if(!empty($result))
		{
			return $result;
		}else{
			return '';
		}
		
	}
}